/*!
 * WPX Javascript Library v1.2
 * Copyright 2014, pony_chiang <jxcent@gmail.com>
 */
// window.console && window.console.info("喜欢看代码，还是发现了什么bug？不如和我一起来讨论吧！\nhttp://www.markdream.com/?pref=wpx_debug");
var wpxLib={
	// 省份地区
	dst:function(object,level,val,sid){
		var value=$(object).val(),domName='';
		if(level==2){
			$('#id_city').remove();
			$('#id_dist').remove();
			domName='id_city';
		}else if(level==3){
			$('#id_dist').remove();
			domName='id_dist';
		}else if(level==4){
			if(sid) value = val;
		}else{
			return;
		}
		
		$.getJSON(url + '&id='+value+'&level='+level,function(data){
			if(level == 4){
				var str = "<option value='0'>选择注册店铺</option>";
				$.each(data,function(i){
					var selected='';
					if(sid==data[i].id){ selected='selected' }; 
					str+='<option value="'+data[i].id+'" '+selected+'>'+data[i].name+'</option>';
				})
				$("#sel_store").html(str);
				if(sid) select_members();
			}else{
				if(data.length==0) return;
				var html=wpxLib.buildSelect(domName,level+1,data,-1,'dst');
				$(object).after(html);
			}
		})
	},
	
	// 组装select DOM
	buildSelect: function(dom,level,data,sid,funstr){
		if(funstr==null) funstr='dsc';
		var html='&nbsp;&nbsp;<select onchange="wpxLib.'+funstr+'(this,'+level+')" name="'+dom+'" id="'+dom+'" class="put"><option value="-1">请选择</option>';
		$.each(data,function(i){
			var str='';
			if(sid==data[i].region_id){
				str='selected';
			}
			html+='<option value="'+data[i].region_id+'" '+str+'>'+data[i].region_name+'</option>';
		})
      	var foot='</select>';
		return html+foot;
	}
};